import createAxios from '/@/utils/axios'

// 获取AI模型列表
export function getAIModels() {
    return createAxios({
        url: 'admin/yxerp.aichat/getModels',
        method: 'get',
    })
}

// 保存AI模型
export function saveAIModel(data: object) {
    return createAxios({
        url: 'admin/yxerp.aichat/saveModel',
        method: 'post',
        data: data
    })
}

// 删除AI模型
export function deleteAIModel(id: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/deleteModel',
        method: 'post',
        data: { id }
    })
}

// 测试模型连接
export function testModelConnection(id: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/testModelConnection',
        method: 'post',
        data: { id }
    })
}

// 获取会话列表
export function getChatConversations(userId: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/getConversations',
        method: 'get',
        params: { user_id: userId }
    })
}

// 创建新会话
export function createChatConversation(data: object) {
    return createAxios({
        url: 'admin/yxerp.aichat/createConversation',
        method: 'post',
        data: data
    })
}

// 更新会话信息
export function updateChatConversation(data: object) {
    return createAxios({
        url: 'admin/yxerp.aichat/updateConversation',
        method: 'post',
        data: data
    })
}

// 删除会话
export function deleteChatConversation(id: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/deleteConversation',
        method: 'post',
        data: { id }
    })
}

// 获取会话消息
export function getChatMessages(conversationId: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/getMessages',
        method: 'get',
        params: { conversation_id: conversationId }
    })
}

// 发送消息
export function sendChatMessage(data: object) {
    return createAxios({
        url: 'admin/yxerp.aichat/sendMessage',
        method: 'post',
        data: data
    })
}

// 上传附件
export function uploadChatAttachment(formData: FormData) {
    return createAxios({
        url: 'admin/yxerp.aichat/uploadAttachment',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 清空会话消息
export function clearChatMessages(conversationId: number) {
    return createAxios({
        url: 'admin/yxerp.aichat/clearMessages',
        method: 'post',
        data: { conversation_id: conversationId }
    })
}

// 获取Ollama模型列表
export function getOllamaModels() {
    return createAxios({
        url: 'admin/yxerp.aichat/getOllamaModels',
        method: 'get'
    })
}

// 获取AI模型列表（从aimodel控制器）
export function getAIModelList() {
    return createAxios({
        url: 'admin/yxerp.aimodel/getModelList',
        method: 'get'
    })
}

// 保存AI模型（到aimodel控制器）
export function saveAIModelConfig(data: object) {
    return createAxios({
        url: 'admin/yxerp.aimodel/saveModel',
        method: 'post',
        data: data
    })
}

// 测试AI模型连接（通过aimodel控制器）
export function testAIModel(data: object) {
    return createAxios({
        url: 'admin/yxerp.aimodel/testModel',
        method: 'post',
        data: data
    })
}

// 从Ollama服务器获取可用模型
export function getOllamaModelTags(endpoint: string) {
    // 由于这是直接请求Ollama服务，需要在前端直接使用axios
    // 这里只是创建一个签名，实际实现需要在前端直接调用
    return {
        url: `${endpoint}/api/tags`,
        method: 'get'
    }
} 